#include<iostream>
#include<algorithm>
using namespace std;
const int N = 1010;
bool st[N];
int arr[N];
int n, q;
int main()
{
	int t;
	cin >> t;
	while (t--) {
		cin >> n >> q;
		for (int i = 0; i < n; i++) {
			cin >> arr[i];
		}
		sort(arr, arr + n);
		int temp = 0;
		int ma = 0;
		for (int i = 0; i < n; i++) {
			temp += arr[i];
			st[arr[i]] = 1;
			if (temp > q) {
				temp -= arr[i];
				st[arr[i]] = 0;
				for (int i = 0; i < n; i++) {
					if (!st[arr[i]]) {
						ma = max(ma, arr[i]);
					}
				}
			}
		}
		cout << temp + ma << endl;
	}
	return 0;
}